//
//  rightSubNewTaskCollectionView.m
//  dataGathering
//
//  Created by apple on 14-11-5.
//  Copyright (c) 2014年 shuili. All rights reserved.
//

#import "rightSubNewTaskCollectionView.h"
#import "mainVC.h"
#import "AFViewShaker.h"


@interface rightSubNewTaskCollectionView ()

@end

@implementation rightSubNewTaskCollectionView

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)cancelButtonClicked:(id)sender {
    
    [((mainVC*)(self.parentViewController.parentViewController.parentViewController)) removeNewTaskCollectionView];
    [((mainVC*)(self.parentViewController.parentViewController.parentViewController)) refreshRightSubView];
}

- (IBAction)createButtonClicked:(id)sender {
    BOOL isEmpty = NO;
    if([_nameLabel.text compare:@""] == NSOrderedSame){
        isEmpty = YES;
        AFViewShaker *shaker = [[AFViewShaker alloc] initWithView:_nameLabel];
        [shaker shakeWithDuration:0.5 completion:^{
            
        }];
        
    }
    if([_descriptionLabel.text compare:@""] == NSOrderedSame){
        isEmpty = YES;
        AFViewShaker *shaker = [[AFViewShaker alloc] initWithView:_descriptionLabel];
        [shaker shakeWithDuration:0.5 completion:^{
            
        }];
    }
    if(!isEmpty){
        currentWorkSetManager *workMgr = [currentWorkSetManager sharedInstance];
        if([workMgr addNewWorkset:[_nameLabel text] :[_descriptionLabel text]])
        {
            [[NSNotificationCenter defaultCenter] postNotificationName:@"refreshTaskCollectionTableView" object:nil];
            [self cancelButtonClicked:nil];
            
        } else {
            
        }
    }
    
    
}
@end
